cc.Class({
    extends: cc.Component,

    properties: {
        getRole:cc.Animation,
        getBtn01:cc.Button,
        getBtn02:cc.Button
    },

    // LIFE-CYCLE CALLBACKS:

    onLoad () {
        //绑定按钮事件：按下即触发
        this.getBtn01.node.on(cc.Node.EventType.TOUCH_START,this.btnClick,this);
        this.getBtn01.node.on(cc.Node.EventType.TOUCH_END,this.btnClick,this);//节点区域内离开
        this.getBtn01.node.on(cc.Node.EventType.TOUCH_CANCEL,this.btnClick,this);//节点区域外离开
        this.getBtn02.node.on(cc.Node.EventType.TOUCH_START,this.btnClick,this);
    },

    //按钮点击/touch事件
    btnClick(e){
        if (this.getRole.currentClip && this.getRole.currentClip._name=='role1-jump') {//判断当前是否有动作且为跳跃
            return;//避免跳跃时能够执行其他动作
        };
        if(e.target._name=='btn-01' && e.type=='touchstart'){
            this.getRole.play('role1-glide');
        }else if(e.target._name=='btn-01' && (e.type=='touchend'||e.type=='touchcancel')){
            this.getRole.play('role1-run');
        }
        else{
            //console.log(this.getRole.node);
            this.getRole.play('role1-jump');
            var moveUp=cc.moveTo(jumpDate/2,cc.v2(jumpUpPos)).easing(cc.easeCubicActionOut());
            var moveDown=cc.moveTo(jumpDate/2,cc.v2(roleDefaultPosition)).easing(cc.easeCubicActionIn());
            var callBack=cc.callFunc(this.jumpOver,this.getRole,this);//执行callBack函数，this是传入回调函数的数据
            var seq=cc.sequence(moveUp,moveDown,callBack);//顺序执行动作
            this.getRole.node.runAction(seq);//执行动作
        }
    },
    //跳跃完成之后callBack函数
    jumpOver(){
        this.play('role1-run')
    }
    // start () {},

    // update (dt) {},
});
